package org.example.pmsystem.controller;
import org.example.pmsystem.Response;
import org.example.pmsystem.entity.Recruit;
import org.example.pmsystem.entity.Resume;
import org.example.pmsystem.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "http://localhost:5173")
@RequestMapping("/resume")
public class ResumeController {
    @Autowired
    private ResumeService resumeService;

    @GetMapping("getAllRecruit")
    public Response<List<Recruit>> getAllRecruit() {
        return Response.newSuccess(resumeService.getAllRecruit());
    }

    @GetMapping("getResumeByUserid/{userid}")
    public Response<List<Resume>> getResumeByUserid(@PathVariable String userid){
        return Response.newSuccess(resumeService.getResumeByUserid(userid));
    }

    @GetMapping("getResumeByStatus/{status}")
    public Response<List<Resume>> getResumeByStatus(@PathVariable String status){
        return Response.newSuccess(resumeService.getResumeByStatus(status));
    }

    @GetMapping("getResumeByDep/{dep}")
    public Response<List<Resume>> getResumeByDep(@PathVariable String dep){
        return Response.newSuccess(resumeService.getResumeByDep(dep));
    }

    @PostMapping("addResume")
    public Response<Boolean> addResume(@RequestBody Resume resume){
        if (resumeService.addResume(resume))
            return Response.newSuccess(null);
        return Response.newFail("请勿重复投递简历");
    }

    @PutMapping("updateResume")
    public Response<Boolean> updateResume(@RequestBody Resume resume){
        if (resumeService.updateResume(resume))
            return Response.newSuccess(null);
        return Response.newFail("更新简历失败");
    }



}